package cn.zhz.springdoc.springboot.config.v3;

import cn.zhz.springdoc.springboot.property.OpenApiProperty;
import cn.zhz.springdoc.springboot.service.impl.OpenApi3ParserImpl;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import org.springdoc.api.AbstractOpenApiResource;
import org.springdoc.core.GroupedOpenApi;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.Primary;

/**
 * @author ZHZ
 * @since 2022-11-16
 */
@ConditionalOnClass({AbstractOpenApiResource.class})
@Import({
        CustomerMultipleOpenApiWebMvcResource.class,
        OpenApi3ParserImpl.class
})
public class OpenApi3Config {


    @Bean
    @Primary
    public OpenAPI openAPICustom(OpenApiProperty openApiProperty) {

        return new OpenAPI().info(new Info().title(openApiProperty.getGroupName())
                .description(openApiProperty.getGroupName())
                .version("v1.0.0"));
    }

    @Bean
    @Primary
    public GroupedOpenApi groupedOpenApiCustom(OpenApiProperty openApiProperty) {
        return GroupedOpenApi.builder()
                .group(openApiProperty.getGroupName())
                .pathsToMatch(openApiProperty.getPathsToMatch())
                .packagesToScan(openApiProperty.getPackagesToScan())
                .build();
    }
}
